#include <bits/stdc++.h>
using namespace std;
#define ar array
#define ll long long
typedef int uci;
#define int long long
#define F first
#define S second
typedef complex<double> cd;
seed_seq seq{
(uint64_t) chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count(),
(uint64_t) __builtin_ia32_rdtsc(),
(uint64_t) (uintptr_t) make_unique<char>().get()
};
mt19937 rng(seq);
// mt19937_64 lrng(seq);
struct debugger{
template <typename T>
debugger& operator<<(T &a){
#ifdef DEBUG
cerr << a;
#endif
return *this;
}
template <typename T>
debugger& operator<<(T &&a){
#ifdef DEBUG
cerr << a;
#endif
return *this;
}
} deb;
const double PI = acos(-1.0);
const int MAX_N = 1e5 + 1;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;
//! function insert
//THINK FIRST, CODE SECOND
//DON'T GET STUCK ON ONE STRATEGY
//CALM DOWNNN FOR ONCE IN YOUR LIFE
//REDUCE
//COUGH E??!?!?!! O.O
//uwu i see you ryan
ar<int, 2> getothers(int no, ar<int, 3> a){
if(a[0] == no)
return {a[1], a[2]};
else if(a[1] == no)
return {a[0], a[2]};
else
return {a[0], a[1]};
}
int getlast(int no, int no2, ar<int, 3> a){
for(int i{}; i < 3; ++i)
if(a[i] != no && a[i] != no2)
return a[i];
return a[0];
}
int notused(vector<int> &a, vector<bool> &used){
for(int i : a)
if(!used[i])
return i;
return -1;
}
void solve() {
int n;
cin >> n;
vector<ar<int, 3>> a(n-2);
for(int i{}; i < n-2; ++i){
cin >> a[i][0] >> a[i][1] >> a[i][2];
sort(a[i].begin(), a[i].end());
}
vector<int> counts(n+1);
for(auto &t : a){
for(int i : t)
counts[i]++;
}
vector<vector<int>> inside(n+1);
for(int j{}; j < n-2; ++j){
for(int i : a[j])
inside[i].push_back(j);
}
map<ar<int, 2>, vector<int>> inds;
for(int i{}; i < n-2; ++i){
inds[{a[i][0], a[i][1]}].push_back(i);
inds[{a[i][0], a[i][2]}].push_back(i);
inds[{a[i][1], a[i][2]}].push_back(i);
}
vector<int> out;
vector<bool> used(n);
for(int i{1}; i <= n; ++i){
if(counts[i] == 1){
out.push_back(i);
int t = inside[i][0];
used[t] = true;
ar<int, 2> others = getothers(i, a[t]);
if(counts[others[0]] == 2){
out.push_back(others[0]);
out.push_back(others[1]);
}else{
out.push_back(others[1]);
out.push_back(others[0]);
swap(others[0], others[1]);
}
while(out.size() < n){
int next = notused(inds[{min(others[0], others[1]), max(others[0], others[1])}], used);
used[next] = true;
int tt = getlast(others[0], others[1], a[next]);
out.push_back(tt);
swap(others[0], others[1]);
others[1] = tt;
}
break;
}
}
for(int i : out)
cout << i << ' ';
cout << '\n';
}
uci main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// cout << "Case #" << t << ": ";
solve();
}
/*
random number generator stuff
num = rng(); gives integer number
num = uniform_int_distribution<int>(a, b)(rng); -> bounds [a, b]
num = uniform_real_distribution<double>(a, b)(rng); -> bounds [a, b)
can also instantiate distributions and call on generator:
uniform_int_distribution<int> thing(a, b);
num = thing(rng);
*/
// struct custom_hash {
// static uint64_t splitmix64(uint64_t x) {
// // http://xorshift.di.unimi.it/splitmix64.c
// x += 0x9e3779b97f4a7c15;
// x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
// x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
// return x ^ (x >> 31);
// }
// size_t operator()(uint64_t x) const {
// static const uint64_t FIXED_RANDOM = lrng();
// return splitmix64(x + FIXED_RANDOM);
// }
// };
964A - Splits | 1615A - Closing The Gap |
4C - Registration System | 1321A - Contest for Robots |
1451A - Subtract or Divide | 1B - Spreadsheet |
1177A - Digits Sequence (Easy Edition) | 1579A - Casimir's String Solitaire |
287B - Pipeline | 510A - Fox And Snake |
1520B - Ordinary Numbers | 1624A - Plus One on the Subset |
350A - TL | 1487A - Arena |
1520D - Same Differences | 376A - Lever |
1305A - Kuroni and the Gifts | 1609A - Divide and Multiply |
149B - Martian Clock | 205A - Little Elephant and Rozdil |
1609B - William the Vigilant | 978B - File Name |
1426B - Symmetric Matrix | 732B - Cormen --- The Best Friend Of a Man |
1369A - FashionabLee | 1474B - Different Divisors |
1632B - Roof Construction | 388A - Fox and Box Accumulation |
451A - Game With Sticks | 768A - Oath of the Night's Watch |